#!/usr/bin/python
# -*- coding: UTF-8 -*-

from kpautos.engine.case import Case
from kptest.config.enum import DeviceType, HostType, DeviceUtility

class openUBMC_CLI_Power_002(Case):
    """
        Name:
            openUBMC_CLI_Power_002
        Label:
            验证CLI接口支持服务器下电
        PreCondition:
            1、BMC正常运行
            2、机器上电状态
        TestStep:
            1、使用ipmcget -d powerstate -v 0命令下电，若下电成功，有结果A）；若下电失败，有结果B）；
        ExpectedResult:
            A）下电成功；
            B）下电失败；
        Parameters:

        Remark:

    """

    # 测试执行前配置等准备操作
    def pre_test_case(self):
        self.device_dut = self.resource.get_device(device_type=DeviceType.Server, utility=DeviceUtility.DUT)
        self.os_host = self.device_dut.get_host(host_type=HostType.HostOS)
        self.cli_api = self.device_dut.get_api(ns_name="BmcCli")

    # 测试步骤
    def procedure(self):
        self.log_step("1、CLI命令下电，有结果A）")
        # power_status = self.cli_api.cli_get_power_state()
        power_off_result = self.cli_api.cli_query_set_server_power_state('set', 0)
        print(f'power off result: {power_off_result}')

        if power_off_result == {'result': 'success'}:
            self.logger.info("A）下电成功；")
        else:
            self.logger.info("B）下电失败；")

    # 测试结束后恢复环境
    def post_test_case(self):
        pass
